package com.anmory.apigateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient
public class ApiGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("auth", r -> r.path("/**")
                        .uri("lb://AuthenticationService"))
                .route("medicine", r -> r.path("/**")
                        .uri("lb://MedicineDataService"))
                .route("personal-center", r -> r.path("/**")
                        .uri("lb://PersonalService"))
                .route("recognition", r -> r.path("/**")
                        .uri("lb://RecognizeService"))
                .route("bot", r -> r.path("/**")
                        .uri("lb://BotService"))
                .route("frontend", r -> r.path("/**") // 匹配所有路径
                        .uri("lb://FrontedService")) // 前端服务的名称
                .build();
    }
}
